import Vuex from 'vuex'
import defaultStatus from '~/store/state/state'
import mutations from '~/store/mutations/mutations'
import getters from '~/store/getters/getters'
import actions from '~/store/actions/actions'

export default () => {
   const store =new Vuex.Store({
        'state': defaultStatus,
        mutations,
        getters,
        actions,
        modules:{
            a:{
                namespaced:true,
                state:{
                    text:1
                },
                mutations:{
                    updateText(state,text){
                     state.text=text
                    }
                },
                //模块类获取全局的getters
                getters:{
                    textPlus(state){
                        return state.text +1
                    }
                }
            },
            b:{
                state:{
                    text:2
                }
            },
            c:{
                state:{
                    text:1
                },
                mutations:{
                    updateText(state,text){
                        state.text=text
                    }
                }
            },


        }
    })
    if(module.hot){
        module.hot.accept([
            './state/state',
            './mutations/mutations',
            './getters/getters',
            './actions/actions'
        ],()=>{
            const  newState=require('./state/state').default
            const  newMutations=require( './mutations/mutations').default
            const  newGetters=require( './getters/getters').default
            const  newActions=require('./actions/actions').default
            store.hotUpdate({
                state:newState,
                mutations:newMutations,
                getters:newGetters,
                actions:newActions
            })
        })

    }
    return store
}